<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <title>
        入库单详情
    </title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="format-detection" content="telephone=no">
    <link rel="stylesheet" href="../../../../css/main.css" media="all">
    <link rel="stylesheet" href="../../../../lib/layui/css/layui_2.5.7.css">
    <script type="text/javascript" src="../../../../lib/loading/okLoading.js"></script>
    <link href="https://cdn.bootcdn.net/ajax/libs/twitter-bootstrap/3.3.5/css/bootstrap.min.css" rel="stylesheet">

</head>

<style>
    /* .layui-form-label {
        width: 112px !important;
    } */
    .layui-tab {
        /* text-align: left !important;
        margin: 10px 0px; */
        overflow: auto !important;
    }
    .layui-upload-file {
        height: 0 !important;
    }

    .table-bordered tr td:nth-child(odd) {
        background: #f1f1f1;
        width: 15%;
    }

    .table-bordered tr td:nth-child(even) {
        width: 16%;
    }

</style>

<body>
<div class="x-body" id="app">
        <div class="layui-tab-content">
            <span style="font-weight:bold">基本信息</span>

            <table class="table table-bordered" style="margin-top: 8px;">
                <tr>
                    <td>入库来源</td>
                    <td>{{joinWarehouseFormData.joinTypeName }}</td>
                    <td>入库库房</td>
                    <td>{{joinWarehouseFormData.warehouseName }}</td>
                    <td>入库日期</td>
                    <td>{{joinWarehouseFormData.joinTime }}</td>
                </tr>
                <tr>
                    <td>采购人员</td>
                    <td>{{joinWarehouseFormData.buyerName }}</td>
                    <td>入库人员</td>
                    <td>{{joinWarehouseFormData.joinerName }}</td>
                    <td>添加时间</td>
                    <td>{{joinWarehouseFormData.addTime }}</td>
                </tr>
                <tr>
                    <td>备注</td>
                    <td colspan="5">{{joinWarehouseFormData.remark }}</td>
                </tr>
            </table>
<!--            joinParts-->




            <!-- <span style="font-weight:bold">账单分期设置<span style="color: red;">*</span></span>
            <div class="layui-form-item" style="margin-top: 8px;">
            </div> -->
            <span style="font-weight:bold">入库配件</span>
            <div class="layui-form-item" style="margin-top: 8px;">
                <table class="layui-table" id="partsTab">
                    <thead>
                        <tr>
                            <th>物料号</th>
                            <th>配件名称</th>
                            <th>规格型号</th>
                            <th>入库数量</th>
                            <th>物料批次</th>
                            <th>供应商</th>
                            <th>配件单价</th>
                            <th>配件总价</th>
                            <th colspan="2">存放位置</th>
                            <th>配件图片</th>
                            <th>采购凭证</th>
                            <th>备注</th>
                            <th>操作</th>
                        </tr>
                    </thead>
                    <tbody id="jineTab">
                        <tr v-for='(item,index) in joinParts'>
                            <td>{{item.partsNum}}</td>
                            <td>{{item.partsName}}</td>
                            <td>{{item.specification}}</td>
                            <td>{{item.partsCount}}</td>
                            <td>{{item.partsMark}}</td>
                            <td>{{item.supplierName}}</td>
                            <td>{{item.partsOneprice}}</td>
                            <td>{{item.partsAllprice}}</td>
                            <td>{{item.site}}</td>
                            <td>
                                <button class="layui-btn layui-btn-xs layui-btn-radius layui-btn" @click="openMsg(item.siteImg)">
                                    <i class="layui-icon">&#xe64a;</i>
                                    {{item.siteImgNum}}
                                </button>
                            </td>
                            <td>
                                <button class="layui-btn layui-btn-xs layui-btn-radius layui-btn" @click="openMsg(item.partsmsgImg)">
                                    <i class="layui-icon">&#xe64a;</i>
                                    {{item.partsmsgImgNum}}
                                </button>

                            </td>
                            <td>
                                <button class="layui-btn layui-btn-xs layui-btn-radius layui-btn" @click="openMsg(item.payEvidenceImg)">
                                    <i class="layui-icon">&#xe64a;</i>
                                    {{item.payEvidenceImgNum}}
                                </button>

                            </td>
                            <td>
                                {{item.partsmsgRemark}}
                            </td>
                            <td>
<!--                                <a title="编辑" lay-event="partsEdit" class="ml-5 layui-btn-xs layui-btn" style="text-decoration:none"></a>-->
                                <button class="layui-btn layui-btn-xs layui-btn-radius layui-btn-normal" @click="openEditPage(item)">
                                    编辑
                                </button>
                            </td>
                        </tr>
                    </tbody>
                </table>
            </div>

<!--            <span style="font-weight:bold">备注信息</span>-->
<!--            <div class="layui-form-item layui-form-text" style="margin-top: 8px;">-->
<!--                <div class="layui-input-block">-->
<!--                    <textarea name="memo" placeholder="合同中一些重要信息或者与甲方的约定等相关信息。" class="layui-textarea" readonly="readonly"></textarea>-->
<!--                </div>-->
<!--            </div>-->
        </div>
 
</div>

<script type="text/html" id="barDemo">
    <a title="编辑" lay-event="view" class="ml-5 layui-btn-xs layui-btn" style="text-decoration:none">编辑</a>
    <a title="删除" href="javascript:;" class="layui-btn-xs layui-btn layui-btn-danger" lay-event="del"
       style="text-decoration:none">
        删除
    </a>
</script>

<script type="text/javascript" src="../../../../js/jquery.min.js"></script>
<script type="text/javascript" src="../../../../js/myAjax.js"></script>
<script type="text/javascript" src="../../../../js/pub.js"></script>
<script src="../../../../lib/layui/layui2.5.7.js" charset="utf-8"></script>
<script src="../../../../js/x-layui.js" charset="utf-8"></script>
<script src="../../../../js/vue.min.js" charset="utf-8"></script>
<script src="https://cdn.bootcdn.net/ajax/libs/twitter-bootstrap/3.3.5/js/bootstrap.min.js"></script>

<script>
    layui.use(['element', 'layer', 'form', 'laydate'], function () {
        $ = layui.jquery;//jquery
        lement = layui.element();//面包导航
        layer = layui.layer;//弹出层
        laydate = layui.laydate;//日期插件
        form = layui.form;
        okLoading.close($);
    })

</script>
<script>

    var recordId = getQueryVariable("recordId");
    var contractId = '';
    layui.use(['laydate', 'table','form', 'layer','upload'],
        function () {
            var laydate = layui.laydate;
            var $ = layui.jquery;
            var form = layui.form;
            var layer = layui.layer;
            // var element = layui.element;
            var table = layui.table;
            var upload = layui.upload;


            table.on('tool(partsTab)', function (obj) { //注：tool 是工具条事件名，test 是 table 原始容器的属性 lay-filter="对应的值"
                let data = obj.data; //获得当前行数据
                let layEvent = obj.event; //获得 lay-event 对应的值（也可以是表头的 event 参数对应的值）
                if (layEvent === 'del') { //删除
                    layer.confirm('是否确认删除 【' + data.supplierName + '】 ？', {
                        icon: 3,
                        title: '提示'
                    }, function (index) {
                        let request = {
                            url: "kf/supplier/deleteSupplier",
                            data: {
                                userId: $userId,
                                supplierId: data.id
                            },
                            method: "POST",
                        };
                        sendRequest(request, (data) => {
                            if (data.code === 0) {
                                layer.msg("删除成功", {
                                    icon: 1
                                });
                                t1.reload();
                            } else {
                                layer.msg("删除失败，请稍后再试！", {
                                    icon: 5
                                });
                            }
                        });
                        layer.close(index);
                    });
                }  else if (layEvent === 'partsEdit') {
                    admin_add2('编辑', 'repeal_join.html?recordId=' + data.id, '95%', '90%')
                }
            });
            //监听类型选择
            // form.on('select(contractType)', function(data) {
            //     getProject(data.value);
            //     setTimeout(() => {
            //         form.render('select');
            //     }, 200);
            // });

            //监听项目选择
            // form.on('select(projectId)', function(data) {
                // getPartyALinkmanId(data.value);
            //     setTimeout(() => {
            //         form.render('select');
            //     }, 200);
            // });

            //多文件列表示例
            var demoListView = $('#demoList')
            ,uploadListIns = upload.render({
                elem: '#testList'
                ,url: 'https://httpbin.org/post' //改成您自己的上传接口
                ,accept: 'file'
                ,multiple: true
                ,auto: false
                ,bindAction: '#testListAction'
                ,choose: function(obj){   
                    var files = this.files = obj.pushFile(); //将每次选择的文件追加到文件队列
                    //读取本地文件
                    obj.preview(function(index, file, result){
                        var tr = $(['<tr id="upload-'+ index +'">'
                        ,'<td>'+ file.name +'</td>'
                        ,'<td>'+ (file.size/1024).toFixed(1) +'kb</td>'
                        ,'<td>等待上传</td>'
                        ,'<td>'
                            ,'<button class="layui-btn layui-btn-xs demo-reload layui-hide">重传</button>'
                            ,'<button class="layui-btn layui-btn-xs layui-btn-danger demo-delete">删除</button>'
                        ,'</td>'
                        ,'</tr>'].join(''));
                        
                        //单个重传
                        tr.find('.demo-reload').on('click', function(){
                        obj.upload(index, file);
                        });
                        
                        //删除
                        tr.find('.demo-delete').on('click', function(){
                            delete files[index]; //删除对应的文件
                            tr.remove();
                            uploadListIns.config.elem.next()[0].value = ''; //清空 input file 值，以免删除后出现同名文件不可选
                        });
                        
                        demoListView.append(tr);
                    });
                }
                ,done: function(res, index, upload){
                    if(res.files.file){ //上传成功
                        var tr = demoListView.find('tr#upload-'+ index)
                        ,tds = tr.children();
                        tds.eq(2).html('<span style="color: #5FB878;">上传成功</span>');
                        tds.eq(3).html(''); //清空操作
                        return delete this.files[index]; //删除文件队列已经上传成功的文件
                    }
                    this.error(index, upload);
                }
                ,error: function(index, upload){
                    var tr = demoListView.find('tr#upload-'+ index)
                    ,tds = tr.children();
                    tds.eq(2).html('<span style="color: #FF5722;">上传失败</span>');
                    tds.eq(3).find('.demo-reload').removeClass('layui-hide'); //显示重传
                }
            });


        });

    const vm = new Vue({
        el: "#app",
        data: {
            joinWarehouseFormData:{},
            joinParts:[],
            // projectId:[],
            // rp: {
            //     id: null,
            //     billType: null,
            //     billAmount: null,
            //     dueDate: null,
            //     personInChargeOfTheBill: null,
            //     relatedCustomers: null,
            //     associatedItems: null,
            //     relatedContract: null,
            //     payer: null,
            //     remark: null,
            //     type: null,
            //     skUnit: null,
            //     yfDate: null,
            // }
        },
        created() {

            // let request = {
            //     url: 'xa/project/findProjectListByTypeIdAndDelFlag',
            //     data: {
            //         userId: $userId,
            //         delFlag:0,
            //         businessTypeId:1
            //     },
            //     method: "get"
            // }
            // sendRequest(request, (res) => {
            //     if(res.code == 0){
            //         for(var i =0;i < res.data.length;i++){
            //             $("#projectListBycontractType").append("<option value=\""+res.data[i].id+"\">"+res.data[i].name+"</option>");
            //         }
            //         //重新渲染
            //         layui.form.render("select");
            //     }else{
            //         layer.msg(res.message);
            //     }
            // })

        },
        computed: {},
        methods: {
            openMsg: function (str) {
                const strdata = "{\"title\": \"\", \"id\": 123,\"start\": 0,\"data\": [";
                let imgdata = "";
                if (str == null) {
                    layer.msg("未上传图片！", {
                        icon: 7
                    });
                    return false;
                }
                const arr = str.split("|");
                for(let i = 0 ; i < arr.length ; i++){
                    if(i == 0){
                        imgdata = imgdata + "{\"alt\": \"图片名\",\"pid\": 666, \"src\": \"" + baseHead +'/other/viewUploadFile?id='+arr[i] + "\",\"thumb\": \"\" }";
                    }else{
                        imgdata = imgdata + ",{\"alt\": \"图片名\",\"pid\": 666, \"src\": \"" + baseHead +'/other/viewUploadFile?id='+arr[i]  + "\",\"thumb\": \"\" }";
                    }
                }
                const jsondata = strdata + imgdata + "]}";
                const obj = JSON.parse(jsondata);
                layer.photos({
                    photos: obj
                    ,shift: 0 //0-6的选择，指定弹出图片动画类型，默认随机（请注意，3.0之前的版本用shift参数）
                });
            },
            openEditPage: function (item) {

                sessionStorage.setItem('partData',JSON.stringify(item));
                this.admin_add2('编辑', 'edit_parts.html', '70%', '70%')
            },
            admin_add2:function (title, url, w, h) {
                layer.open({
                    type: 2,
                    area: [w, h],
                    fix: false, //不固定
                    maxmin: true,
                    shadeClose: true,
                    shade: 0.4,
                    offset: ['20px', '20px'],
                    title: title,
                    content: url
                });
            }
        },
        mounted() {
            var that = this;
            let request = {
                url: 'kf/partsJoinWarehouse/getJoinWarehouseFormMsg',
                data: {
                    userId: $userId,
                    joinFormId: recordId
                },
                method: "GET",
            };
            sendRequest(request, (res) => {
                if(res.code == 0){
                    that.joinWarehouseFormData = res.data.JoinWarehouseFormMsg[0].JoinWarehouseFormData[0];
                    that.joinParts = res.data.JoinWarehouseFormMsg[1].joinParts;
                    for(var i =0;i < that.joinParts.length;i++){
                        // $("#warehouseId").append("<option value=\""+res.data.WarehouseTypeData[i].id+"-"+res.data.WarehouseTypeData[i].name+"\">"+res.data.WarehouseTypeData[i].name+"</option>");

                        // that.joinParts[i].siteImgNum = that.joinParts[i].siteImg.split("|").length;
                        // that.joinParts[i].partsmsgImgNum = that.joinParts[i].partsmsgImg.split("|").length;
                        // that.joinParts[i].payEvidenceImgNum = that.joinParts[i].payEvidenceImg.split("|").length;
                        if (that.joinParts[i].siteImg == null || that.joinParts[i].siteImg == '') {
                            that.joinParts[i].siteImgNum = 0;
                        }else {
                            that.joinParts[i].siteImgNum = that.joinParts[i].siteImg.split("|").length;
                        }

                        if (that.joinParts[i].partsmsgImg == null || that.joinParts[i].partsmsgImg == '') {
                            that.joinParts[i].partsmsgImgNum = 0;
                        }else {
                            that.joinParts[i].partsmsgImgNum = that.joinParts[i].partsmsgImg.split("|").length;
                        }

                        if (that.joinParts[i].payEvidenceImg == null || that.joinParts[i].payEvidenceImg == '') {
                            that.joinParts[i].payEvidenceImgNum = 0;
                        }else {
                            that.joinParts[i].payEvidenceImgNum = that.joinParts[i].payEvidenceImg.split("|").length;
                        }
                    }
                }else{
                    layer.msg(res.message);
                }
            });
        },


    });

    // setTimeout(() => {
    //     //修改状态
    //     let form = layui.form;
    //     //账单类型
    //     let request = {
    //         url: 'dictionary/findDataDictionaryValue',
    //         data: {
    //             userId: $userId,
    //             label: 'BILL_TYPE'
    //         },
    //         method: "POST",
    //     };
    //     sendRequest(request, (res) => {
    //         let x = res.data;
    //         $.each(x, function (index, item) {
    //             let opt = $("<option value=" + item + ">" + item + "</option>");
    //             $("select[name=billType]").append(opt);

    //         });

    //         $("select[name=billType]").val(vm.rp.billType);

    //         form.render('select');
    //     });
    // }, 300)

</script>

</body>

</html>
